package com.qyer.util.log.util;

import java.util.HashMap;
import java.util.Map;

import com.qyer.util.log.common.Constants;

public class HiveFormatUtil {
	public  static String getFeild(String feild) {
 		if(feild==null||feild.equalsIgnoreCase("null")||"".equalsIgnoreCase(feild.trim())){
 			return "-";
 		}
 		return feild; 
 	}
	 
	public  static String getMapFeild(Map <String ,String> maps) {
		StringBuilder  res = new StringBuilder ("");
		
 		if(maps==null||maps.size()==0){
 			return "-";
 		}
 		
 		for(String k : maps.keySet()){
 			res.append(k).append(Constants.MAP_FS).append(maps.get(k)).append(Constants.COLLECTION_FS);
 		}
 		
 		return res.substring(0 , res.length()-1); 
 	}
	
	public  static String getMapFeild2(Map <String ,Object> maps) {
		StringBuilder  res = new StringBuilder ("");
		
 		if(maps==null||maps.size()==0){
 			return "";
 		}
 		
 		for(String k : maps.keySet()){
 			res.append(k).append(Constants.MAP_FS).append(maps.get(k)).append(Constants.COLLECTION_FS);
 		}
 		
 		return res.substring(0 , res.length()-1); 
 	}
	
	
	public  static Map <String ,String>  toMapOfFS(String str) {
		Map <String ,String> maps = new HashMap<String,String>();
		
 		if(str==null||"".equals(str.trim())){
 			return null;
 		}
 		
 		String [] fs = str.split(Constants.COLLECTION_FS);
 		
 		for(String k : fs){
 			String []ks = k.split(Constants.MAP_FS);
 			if(ks.length>1){
 				maps.put(ks[0], ks[1]);
 			}
 		}
 		
 		return maps; 
 	}
	
	public static void main(String[] args) {
		Map<String ,String>rest = new HashMap<String ,String>();
		rest.put("a", "av");
		rest.put("b", "bv");
		
		System.out.println(getMapFeild(rest));
	}
}
